package service.Serviceimpl;

import domain.solr;
import domain.student;
import service.studentService;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class SudentServiceImpl  implements studentService {
    @Override
    public student login(student student) throws SQLException {
        String sql="SELECT * FROM student  WHERE s_user=? AND  s_password =?";

        return stu.login(sql,student);
    }

    @Override
    public List<student> findAll(String fzid,String studentname) throws SQLException {
        String sql="SELECT * FROM student where 1=1";
        ArrayList<Object> objects = new ArrayList<>();

        if(fzid!=null&&fzid!=""){
            sql=sql+" and s_groupid =?";
            objects.add(fzid);
        }
        if(studentname!=null&&studentname!=""){
            sql=sql+" AND s_name LIKE (?)";
            studentname=studentname+"%";
            objects.add(studentname);
        }

        System.out.println(sql);
        return  stu.findAll(sql,objects);
    }

    @Override
    public List<solr> findSolr(String name) {
        String sql="SELECT s.s_name\n" +
                "FROM solr s,role r,solrrole sr,student st,studentrole ur\n" +
                "WHERE s.s_id=sr.s_id\n" +
                "AND r.r_id=sr.r_id\n" +
                "AND st.s_id=ur.s_id\n" +
                "AND r.r_id=ur.r_id\n" +
                "AND st.s_name=?" +
                "AND pop=1";

        return  stu.findSolr(sql,name);
    }
}
